package org.smile.db.pool;

import java.io.Serializable;
import java.util.ResourceBundle;
/**
 * 连接池参数
 * @author strive
 *
 */
public class DataSourceParam implements Serializable {
	 /**
	  *  数据库驱动程序
	  */
	private String driver; 
	// 数据连接的 URL 
	private String url; 	
	 // 数据库用户名
	private String user; 
	 // 数据库密码
	private String password; 
	// 初始化连接数
	private int minConnection = 0; 
	 // 最大连接数
	private int maxConnection = 50; 
	// 连接的最大空闲时间
	private long timeoutValue = 600000;
	 //等待时间
	private long waitTime = 30000;
	
	public DataSourceParam(){}
	
	public DataSourceParam(String driver,String url,String user,String password){
		this.driver=driver;
		this.url=url;
		this.user=user;
		this.password=password;
	}
	
	public DataSourceParam(String configFile) throws Exception{
		try{
			ResourceBundle dbResources = ResourceBundle.getBundle(configFile);
			String driver=dbResources.getString("dbDriver");
			String url=dbResources.getString("dbUrl");
			String user=dbResources.getString("dbUser");
			String password=dbResources.getString("dbPassword");
			String maxConn=dbResources.getString("maxConnection");
			String minConn=dbResources.getString("minConnection");
			String timeoutValue=dbResources.getString("timeoutValue");
			String waitTime=dbResources.getString("waitTime");
			this.setDriver(driver);
			this.setUrl(url);
			this.setUser(user);
			this.setPassword(password);
			if(maxConn!=null){
				this.maxConnection=Integer.parseInt(maxConn);
			}
			if(minConn!=null){
				this.minConnection=Integer.parseInt(minConn);
			}
			if(timeoutValue!=null){
				this.timeoutValue=Integer.parseInt(timeoutValue);
			}
			if(waitTime!=null){
				this.waitTime=Integer.parseInt(waitTime);
			}
		}catch(Exception e){
			throw new Exception("从一个properties文件构造数据源参数失败",e);
		}
	}
	public String getDriver() {
		return driver;
	}
	public void setDriver(String driver) {
		this.driver = driver;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getUser() {
		return user;
	}
	public void setUser(String user) {
		this.user = user;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public int getMinConnection() {
		return minConnection;
	}
	public void setMinConnection(int minConnection) {
		this.minConnection = minConnection;
	}
	public int getMaxConnection() {
		return maxConnection;
	}
	public void setMaxConnection(int maxConnection) {
		this.maxConnection = maxConnection;
	}
	public long getTimeoutValue() {
		return timeoutValue;
	}
	public void setTimeoutValue(long timeoutValue) {
		this.timeoutValue = timeoutValue;
	}
	public long getWaitTime() {
		return waitTime;
	}
	public void setWaitTime(long waitTime) {
		this.waitTime = waitTime;
	}
	 
	 
}
